package com.mini.gateway.util;

import org.springframework.util.AntPathMatcher;

import java.util.Collection;

/**
 * 路径工具类
 *
 * @author Zhou Feng
 */
public class PathUtils {

    /**
     * 判断url是否匹配pattern列表中的任意一个
     */
    public static boolean isMatchAny(Collection<String> patterns, String path) {
        if (patterns == null || patterns.isEmpty()) {
            return false;
        }
        AntPathMatcher matcher = new AntPathMatcher();
        for (String pattern : patterns) {
            if (matcher.match(pattern, path)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断url是否匹配pattern
     */
    public static boolean isMatchOne(String pattern, String path) {
        AntPathMatcher matcher = new AntPathMatcher();
        return matcher.match(pattern, path);
    }
}
